package cn.wen.eeayjoke;

import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;

import java.lang.reflect.Method;
import java.util.Arrays;
import butterknife.BindView;
import cn.wen.base.adapter.recyclerview.QuickRecyclerAdapter;
import cn.wen.base.adapter.recyclerview.QuickRecyclerViewHolder;
import cn.wen.base.decoration.LinearItemDecoration;
import cn.wen.core.titlebar.DefTitleBar;
import cn.wen.core.ui.AppActivity;
import cn.wen.eeayjoke.ui.BuglyTestActivity;
import cn.wen.eeayjoke.ui.CountdownActivity;
import cn.wen.eeayjoke.ui.LoadingTestActivity;
import cn.wen.eeayjoke.ui.NetTestActivity;
import cn.wen.eeayjoke.ui.PayTestActivity;
import cn.wen.eeayjoke.ui.PullZoomTestActivity;
import cn.wen.eeayjoke.ui.RefreshTestActivity;
import cn.wen.eeayjoke.ui.RxjavaActivity;
import cn.wen.eeayjoke.ui.SelectedImageTestActivity;
import cn.wen.eeayjoke.ui.ShareTestActivity;
import cn.wen.eeayjoke.ui.WebTestActivity;
import cn.wen.eeayjoke.ui.XImageViewTestActivity;
import cn.wen.eeayjoke.ui.ZxingTestActivity;

/**
 * 测试主页面
 */
public class MainActivity extends AppActivity {

    @BindView(R.id.recycler_view)
    RecyclerView mRecyclerView;
    private Class[] mActivities = new Class[]{
            SelectedImageTestActivity.class,
            ZxingTestActivity.class,
            RefreshTestActivity.class,
            ShareTestActivity.class,
            WebTestActivity.class,
            LoadingTestActivity.class,
            XImageViewTestActivity.class,
            BuglyTestActivity.class,
            NetTestActivity.class,
            PayTestActivity.class,
            PullZoomTestActivity.class,
            RxjavaActivity.class,
            CountdownActivity.class
    };
    private QuickRecyclerAdapter<Class> mAdapter;

    @Override
    public Object getContentLayout() {
        return R.layout.activity_main;
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        // 取消侧划返回
        setSwipeBackEnable(false);
        // initResources();
    }

    private void initResources() {
        try {
            // 1. 创建资源管理类---AssetManager
            AssetManager assetManager = AssetManager.class.newInstance();
            String skinPath = "";
            Method method = AssetManager.class.getDeclaredMethod("addAssetPath", String.class);
            // 2. 添加皮肤路径
            method.invoke(assetManager, skinPath);
            // 3. 加载资源
            Resources resources = new Resources(assetManager, new DisplayMetrics(), new Configuration());
            int drawableId = resources.getIdentifier("src_image", "drawable", "cn.wen.skin");
            Drawable drawable = resources.getDrawable(drawableId);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Override
    public void initView(View contentView) {
        mAdapter = new QuickRecyclerAdapter<Class>(this, Arrays.asList(mActivities), R.layout.item_main_test) {
            @Override
            protected void convert(QuickRecyclerViewHolder holder, final Class item, int position) {
                holder.setText(R.id.tv, item.getSimpleName());
                holder.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        startActivity(item);
                        finish();
                    }
                });
            }
        };
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        // 添加分割线
        mRecyclerView.addItemDecoration(new LinearItemDecoration(this));
        mRecyclerView.setAdapter(mAdapter);
    }


    @Override
    protected void initTitle(DefTitleBar titleBar) {
        titleBar.setTitle("主页面");
        // 隐藏返回按钮
        titleBar.clearBackClick();
    }


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.e("TAG","main-->onCreate");
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.e("TAG","main-->onResume");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.e("TAG","main-->onStop");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.e("TAG","main-->onDestroy");
    }
}
